<template>
    <van-nav-bar
    title="填写评价"
    right-text="提交"
    left-arrow
    @click-left="onClickLeft"
    @click-right="onClickRight"
    class="custom-submit-button"
  />
  <van-cell-group inset>
    <van-field
      v-model="message"
      rows="2"
      autosize
      label="请输入评价"
      type="textarea"
      maxlength="30"
      placeholder="请输入评价"
      show-word-limit
    />
  </van-cell-group>
  <div class="rate">
    <h4>请对陪诊人{{ escort }}评分</h4>
    <van-rate v-model="value"
    allow-half
    color="#ffd21e"
    @change="onChange" />
  </div>
</template>
<script setup>
import { ref, onMounted } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import { showToast } from 'vant';
import http from '@/http';
let value = ref(0);
let route = useRoute();
let router = useRouter();
let escort = ref({});
let message = ref('');

onMounted(() => {
  escort.value = route.query.escort;
  console.log(escort.value);
})
let onClickLeft = () => {
  router.push('/totalorder')
}

const onChange = (value) => {
  value = value;
  console.log(value);
};

function onClickRight() {
  if(value.value == 0){
    showToast('请评分');
  }else{
    http.post('/patient/evaluateOrder/', {
      escort: escort.value,
      evaluate: value.value,
      message: message.value
    }).then(res => {
      console.log(res);
        showToast('评价成功');
        router.push('/totalorder')
    }
  ).catch(err => {
    console.log(err);
  })
  }
}
</script>
<style scoped>
.rate {
  width: 90%;
  margin-left: 5%;
}
</style>
